package net.jxiny.oschina.tweet.TweetActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.okhttplib.HttpInfo;
import com.okhttplib.OkHttpUtil;
import com.okhttplib.callback.Callback;

import net.jxiny.oschina.R;
import net.jxiny.oschina.net.URLList;
import net.jxiny.oschina.util.ACache;

import java.io.IOException;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SendTweetActivity extends AppCompatActivity {


    @BindView(R.id.tweet_cancel)
    ImageView tweetCancel;
    @BindView(R.id.tweet_write)
    EditText tweetWrite;
    @BindView(R.id.tweet_send_information)
    TextView tweetSendInformation;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_move);
        ButterKnife.bind(this);
    }
    @OnClick({ R.id.tweet_cancel,R.id.tweet_send_information})
    public void onViewCliked(View view){
        switch (view.getId()){
            case R.id.tweet_cancel:
                finish();
                break;
            case R.id.tweet_send_information:
                OkHttpUtil.getDefault(this)
                        .doGetAsync(HttpInfo.Builder().setUrl(URLList.SEND_ADD_BACK +"?msg="+tweetWrite
                                .getText().toString()+"&access_token="+
                                ACache.get(this).getAsString("token")).build(), new Callback() {
                            @Override
                            public void onSuccess(HttpInfo info) throws IOException {
                                Toast.makeText(SendTweetActivity.this,"发送成功",Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public void onFailure(HttpInfo info) throws IOException {
                                Toast.makeText(SendTweetActivity.this,"发送失败",Toast.LENGTH_SHORT).show();
                            }
                        });
        }
    }

}
